using System;
using System.Collections.Generic;
using System.Text;

namespace Academia.BI
{
    public partial class Page: System.Web.UI.Page
    {
        #region Constructor

        public Page() : base()
        {
            
        }

        #endregion

        #region Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(Page.IsPostBack))
                    LogPageVisited();
        }
        
        protected void Page_Init(object sender, EventArgs e)
        {
            Load += new EventHandler(Page_Load);
        }

        #endregion


        public void LogPageVisited()
        {
            try
            {
                StringBuilder sqlCommand = new StringBuilder(
                    @"set language portuguese Insert INTO PageVisited (Dia, AccessID, 
                  QueryString, QueryStringReferrer, UrlReferrer,
                  Url) VALUES ");
                sqlCommand.AppendFormat("(GetDate(), {0}, '{1}',", Session["AccessID"], Request.Url.Query);
                if (Request.UrlReferrer != null)
                    sqlCommand.AppendFormat("'{0}', '{1}',", Request.UrlReferrer.Query, Request.UrlReferrer.AbsoluteUri);
                else 
                    sqlCommand.Append("'', '', ");
                sqlCommand.AppendFormat("'{0}')", Request.Url.AbsoluteUri);
              
                SqlDataManager.ExecuteNonQuery(sqlCommand.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        
    }
}
